<?php


/**
 *
 *
 * @author qle4
 * @version $Id$
 * @package system.web.helpers
 * @since 1.0
 */
class WebUtils
{
	public static function shorten($text, $len)
	{
		$tail = max(0, $len-10);
		$trunk = substr($text, 0, $tail);
		$trunk .= strrev(preg_replace('~^..+?[\s,:]\b|^...~', '...', strrev(substr($text, $tail, $len-$tail))));
		return $trunk;
	}
	
	public static function count(){
		$counter = Counter::model()->find();
		if (isset(Yii::app()->session['visitor']) ||  Yii::app()->session['visitor'] == 1){
			
		} else {
			$counter->number = $counter->number+1;
			$counter->save();
			Yii::app()->session['visitor'] = 1;
			
		}
		
		return $counter->number;
	}
	
	public static function  getYouTubeIdFromURL($url)
	{
		$url_string = parse_url($url, PHP_URL_QUERY);
		parse_str($url_string, $args);
		return isset($args['v']) ? $args['v'] : false;
	}
}
